import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class FlowerList {
	private List<Flower> flowers = new ArrayList<Flower>();
	public List<Flower> getFlowers(){
		return flowers;
	}
	public void addFlower(Flower flower){
		this.flowers.add(flower);
	}
	public Flower find(String number){
		for(Flower flower : flowers){
			if(flower.getNumber().equals(number)){
				return flower;
			}
		}
		return null;
	}
	public FlowerList(){
		try {
			BufferedReader reader = new BufferedReader(new FileReader(new File("Flowers.txt")));
			reader.readLine();
			String line = "";
			while((line = reader.readLine())!=null){
				line = line.replaceAll("\\s{1,}", " ");
				String lines[] = line.trim().split(" ");
				if(lines.length==3){
					String number = lines[0];
					String name = lines[1];
					double price = Double.parseDouble(lines[2]);
					flowers.add(new Flower(number,name,price));
				}
			}
			reader.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
